<?php

namespace App\Jobs;

use App\Models\STeaScheduleInfo;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class NewTeacherAddSchedule implements ShouldQueue {
	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

	var $teacher_id;
	/**
	 * Create a new job instance.
	 *
	 * @return void
	 */
	public function __construct($teacher_id) {
		$this->teacher_id = $teacher_id;
		logger("NewTeacherAddSchedule:teacher_id:" . $this->teacher_id);
	}

	/**
	 * Execute the job.
	 * 直接生成 5周时间的老师值班表
	 * @return void
	 */
	public function handle() {
		logger(" NewTeacherAddSchedule  handle ... ");

		//
		$teacher_id = $this->teacher_id;

		$startWeek = Carbon::now()->addWeeks(-1)->startOfWeek();
		//5*7=35
		for ($i = 0; $i < 35; $i++) {

			$date = $startWeek->copy()->addDay($i)->toDateString();
			STeaScheduleInfo::firstOrCreate([
				'date_time' => $date,
				'teacher_id' => $teacher_id,
			]);
		}

	}

}
